package com.wm.wmim.server.dbservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wm.wmim.server.dao.ChatListDao;
import com.wm.wmim.server.entity.ChatListDO;
import com.wm.wmim.server.dbservice.ChatListDbService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 聊天列表表(ChatList)表服务实现类
 *
 * @author weiming
 * @since 2025-02-20 23:16:30
 */
@Service
public class ChatListDbServiceImpl extends ServiceImpl<ChatListDao, ChatListDO> implements ChatListDbService {

    @Override
    public ChatListDO getByUserIdAndFriendID(Long userId, Long friendId) {
        LambdaQueryWrapper<ChatListDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChatListDO::getUserId, userId);
        queryWrapper.eq(ChatListDO::getFriendId, friendId);
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper) ;
    }

    @Override
    public List<ChatListDO> listByUserId(Long userId) {
        LambdaQueryWrapper<ChatListDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChatListDO::getUserId, userId);
        return this.list(queryWrapper) ;
    }
}

